<?php

require_once BaseUtil::getModulePath("base")  .  '/forms/BaseForm.php';
require_once   BaseUtil::getModulePath("base")  .  '/validate/Unique.php';
require_once   BaseUtil::getModulePath("metadata")  .  '/constants/MetadataConstant.php';

class MetadataForm extends BaseForm {

    public function __construct ($metadataId = null){

        parent::__construct();
        if(isset($metadataId)){
            $this->setAction(HttpUtil::getUrl("metadata", "subedit"));
        }else{
            $this->setAction(HttpUtil::getUrl("metadata", "subadd"));
        }
        $id = new Zend_Form_Element_Hidden("id");
        $inputTypeValue = new Zend_Form_Element_Hidden("inputTypeValue");
        //element code
        $code = new Zend_Form_Element_Text("code");
        $code->setLabel($this->translate->_('code'));
        $code->addFilter("StringTrim");
        $code->setRequired(true);

        $validUniqueCode = new MyValid_Unique();
        $validUniqueCode->setFetchAttr('metadatas', 'code');
        if(isset($metadataId)){
            $validUniqueCode->setId($metadataId);
        }
        
        if(isset($metadataId)){
            //$code->setAttrib("readonly", "readonly");
        }else{
        	
        }
        $code->addValidator($validUniqueCode);
        
        //element title
        $title = new Zend_Form_Element_Text("title");
        $title->setLabel($this->translate->_('title'));
        $title->addFilter("StringTrim");
        $title->setRequired(true);
        //element long title
        $longTitle = new Zend_Form_Element_Text("longTitle");
        $longTitle->setLabel($this->translate->_('longTitle'));
        $longTitle->addFilter("StringTrim");
        //element input type
        $inputType = new Zend_Form_Element_Select('inputType');
        $inputType->setLabel($this->translate->_('inputType'));
        $inputType->setAttrib("onchange", "javascript:MetadataSet.changeInput();");
        $inputType->setAttrib("id", "inputType");
        $inputType->setMultiOptions(MetadataConstant::getInputTypeList());
        if(isset($metadataId)){
            $inputType->setAttrib("disable", "disable");
        }
        
        //element required
        $level = new Zend_Form_Element_Select('level');
        $level->setLabel($this->translate->_('level'));
        $level->setMultiOptions(array("1"=>$this->translate->_('pLevel'),"2"=>$this->translate->_('iLevel')));
        
        //element required
        $valueRequired = new Zend_Form_Element_Select('valueRequired');
        $valueRequired->setLabel($this->translate->_('valueRequired'));
        $valueRequired->setMultiOptions(array("0"=>$this->translate->_('noLabel'),"1"=>$this->translate->_('yesLabel')));
        //description
        $description = new Zend_Form_Element_Textarea('description');
        $description->setLabel($this->translate->_('description'));
        $description->addFilter("StringTrim");
        //in_basic_search
        $inBasicSearch = new Zend_Form_Element_Select("inBasicSearch");
        $inBasicSearch->setLabel($this->translate->_('inBasicSearch'));
        $inBasicSearch->setMultiOptions(array("0"=>$this->translate->_('noLabel'),"1"=>$this->translate->_('yesLabel')));

        //in_advance_search
        $inAdvanceSearch = new Zend_Form_Element_Select("inAdvanceSearch");
        $inAdvanceSearch->setLabel($this->translate->_('inAdvanceSearch'));
        $inAdvanceSearch->setMultiOptions(array("0"=>$this->translate->_('noLabel'),"1"=>$this->translate->_('yesLabel')));

        //is_primary
        $isPrimary = new Zend_Form_Element_Select("isPrimary");
        $isPrimary->setLabel($this->translate->_('isPrimary'));
        $isPrimary->setMultiOptions(array("0"=>$this->translate->_('noLabel'),"1"=>$this->translate->_('yesLabel')));
        
        
        
        //show_in_product
        $showInProduct = new Zend_Form_Element_Select("showInProduct");
        $showInProduct->setLabel($this->translate->_('showInProduct'));
        $showInProduct->setMultiOptions(array("0"=>$this->translate->_('noLabel'),"1"=>$this->translate->_('yesLabel')));

                
        //sort_order
        $sortOrder = new Zend_Form_Element_Text("sortOrder");
        $sortOrder->setLabel($this->translate->_('sortOrder'));
        $sortOrder->addFilter("StringTrim");

        $this->addElements(array($id,$inputTypeValue,$code,$title,$longTitle,$inputType,$valueRequired,$description,$inBasicSearch,$inAdvanceSearch,$isPrimary,$showInProduct,$sortOrder,$level));

        $this->setElementDecorators(array(
            'ViewHelper',
            array(array('div' => 'HtmlTag'), array('tag' => 'div',"class" => "form_element")),
        ));
    }
}